cmake_minimum_required (VERSION 2.8.4)

project (FORMIC C CXX Fortran)

if (${CMAKE_OSX_ARCHITECTURES} MATCHES "x86_64")
  set(CMAKE_SYSTEM_PROCESSOR "x86_64")
endif (${CMAKE_OSX_ARCHITECTURES} MATCHES "x86_64")

## find MPI
#find_package(MPI)
#message("        MPI_CXX_FOUND:   ${MPI_CXX_FOUND}")
#message("     MPI_CXX_COMPILER:   ${MPI_CXX_COMPILER}")
#message("MPI_CXX_COMPILE_FLAGS:   ${MPI_CXX_COMPILE_FLAGS}")
#message(" MPI_CXX_INCLUDE_PATH:   ${MPI_CXX_INCLUDE_PATH}")
#message("   MPI_CXX_LINK_FLAGS:   ${MPI_CXX_LINK_FLAGS}")
#message("    MPI_CXX_LIBRARIES:   ${MPI_CXX_LIBRARIES}")
##if(NOT MPI_CXX_FOUND)
##  message(FATAL_ERROR "Failed to find the MPI C++ compiler.")
##endif(NOT MPI_CXX_FOUND)

# initialize variable to hold library link flags
set(MY_CXX_LIB_FLAGS)

# library linking flag for mpi libraries in a non-standard location
if(USE_MPI)
  if(MPI_LIBRARY_DIR)
    set(MY_CXX_LIB_FLAGS "${MY_CXX_LIB_FLAGS} -L${MPI_LIBRARY_DIR}")
  endif(MPI_LIBRARY_DIR)
endif(USE_MPI)

#set flags
set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g ${MY_CXX_LIB_FLAGS}")
set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG ${MY_CXX_LIB_FLAGS}")
set(CMAKE_Fortran_FLAGS_DEBUG "-O0 -g")
set(CMAKE_Fortran_FLAGS_RELEASE "-O2")

# show the install location
message("-- Installation directory set to ${CMAKE_INSTALL_PREFIX}")

# show the source directory
message("-- Source directory set to ${FORMIC_SOURCE_DIR}")

# show the binary directory
message("-- Binary directory set to ${FORMIC_BINARY_DIR}")

# set default build type to be RELEASE
if (NOT CMAKE_BUILD_TYPE)
  set(CMAKE_BUILD_TYPE RELEASE)
endif()

# show the build type
message("-- Build type is ${CMAKE_BUILD_TYPE}")

# show the system processor type
message("-- System processor is ${CMAKE_SYSTEM_PROCESSOR}")

# determine the fortran/c interface
include(FortranCInterface)
#FortranCInterface_VERIFY(CXX)

# make sure we have pthreads
find_package(Threads)
if(NOT CMAKE_USE_PTHREADS_INIT)
  message(FATAL_ERROR "pthreads not found.")
endif(NOT CMAKE_USE_PTHREADS_INIT)

# find the boost header files
find_package(Boost)
if(NOT Boost_FOUND)
  message(FATAL_ERROR "Failed to find the Boost C++ header files.")
endif(NOT Boost_FOUND)

# find blas and lapack
include(${FORMIC_SOURCE_DIR}/FindLapack.cmake)
message("-- BLAS will be linked with   ${BLAS_LIBRARIES}")
message("-- LAPACK will be linked with   ${LAPACK_LIBRARIES}")

# find psi3
include(${FORMIC_SOURCE_DIR}/FindPsi3.cmake)

# enable testing
enable_testing()

# process the code files
add_subdirectory (src)
